package com.boot.persistence.condition;

import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author 霜寒 <1621856595@qq.com>
 * @description 排序条件
 * @date 2020/6/4 0:14
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@ApiModel(value = "排序条件对象")
public class OrderCondition {

    @ApiModelProperty(value = "字段名数组", name = "columns")
    private List<String> columns;
    @ApiModelProperty(value = "升序or降序", name = "mode", notes = "true:升序;false:降序")
    private Boolean mode;

    public void camelToUnderline() {
        if (!CollectionUtils.isEmpty(columns)) {
            int size = columns.size();
            for (int i = 0; i < size; i++) {
                columns.set(i, StrUtil.toUnderlineCase(columns.get(i)));
            }
        }
    }
}
